//
//  FLDViewViewController.m
//  FLDView
//
//  Created by 深津 貴之 on 09/08/05.
//  Copyright __MyCompanyName__ 2009. All rights reserved.
//

#import "FLDViewViewController.h"
#import "FLDView.h"

@implementation FLDViewViewController




// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	self.view.backgroundColor = [UIColor blackColor];
	
	FLDView *fldv = [[FLDView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
	fldv.backgroundColor = [UIColor redColor];
	fldv.x = 160;
	fldv.y = 120;
	fldv.delegate = self;
	[fldv updateTransform];	//Call this method after you set transform property.
	[self.view addSubview:fldv];
	
	fldv = [[FLDView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
	fldv.backgroundColor = [UIColor greenColor];
	fldv.x = 160;
	fldv.y = 240;
	fldv.delegate = self;
	[fldv updateTransform];	//Call this method after you set transform property.
	[self.view addSubview:fldv];
	
	fldv = [[FLDView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
	fldv.backgroundColor = [UIColor blueColor];
	fldv.x = 160;
	fldv.y = 360;
	fldv.delegate = self;
	[fldv updateTransform];	//Call this method after you set transform property.
	[self.view addSubview:fldv];
}


//delegete method for FLDView touch event
-(void)view:(FLDView*)theView touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
	[[theView superview] bringSubviewToFront:theView];
	
	NSLog(@"touches began");
	[UIView beginAnimations:nil context:nil];
	[UIView setAnimationDuration:0.5];
	theView.x = rand()%320;
	theView.y = rand()%480;
	theView.rotation = rand()%360;
	theView.scaleX = 0.5 + rand()%100/100.0;
	theView.scaleY = 0.5 + rand()%100/100.0;
	[theView updateTransform];
	[UIView commitAnimations];
}




- (void)dealloc {
    [super dealloc];
}

@end
